public class ConstantPool {
    public static void main(String[] args) throws Exception {
        // one
        String v1 = new String("xxt");
        String v2 = new String("xxt");
        System.out.println(v1 == v2);
        System.out.println(v1.equals(v2));
        System.out.println("======================");
        // two
        String v3 = "xxt";
        String v4 = "xxt";
        System.out.println(v4 == v3);
        System.out.println(v1 == v3);
        System.out.println("======================");
        // three
        String v5 = "ab" + "cd";
        String v6 = "abcd";
        System.out.println(v5 == v6);
        System.out.println("======================");
        // four
        String v71 = "a";
        String v72 = "b";
        String v7 = v71 + v72;
        String v8 = "ab";
        String v9 = v71 + "b";
        System.out.println(v7 == v8);
        System.out.println(v9 == v8);
        System.out.println("======================");
        // five
        String v10 = v7.intern();
        System.out.println(v10 == v8);
        System.out.println("======================");
        // six
        final String v11 = v71 + v72; // v71, v72 普通（非final）变量，JVM 会创建一个新的字符串对象来存储结果 "ab"，这个新对象不是常量池中的对象
        System.out.println(v11 == v8);
        final String v12 = "b";
        String v13 = "a" + v12;
        System.out.println(v13 == v8);
    }
}
